<template>
  <el-upload
  class="avatar-uploader jx-uploader"
  name="imgFile"
  :headers="headers"
  :action="url"
  :show-file-list="false"
  :on-success="handleSuccess">
  <img v-if="(item.logoImgUrl != '') && (item.logoImgUrl)" :src="item.logoImgUrl" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload> 
</template>
<script>
export default {
  props: {
    item: {
      default: {logoImgUrl: "", logoName: "",logoImgId: ""},
      type: String
    },
    url: String,
    path: {
      default: 'index',
      type: String
    }
  },
  data(){
    return {
      headers: {
        'admin-auth-token': localStorage.getItem('ms_token') || ''
      },
    }
  },
  methods: {
    handleSuccess(res){
      let _self = this
      if(!res) return
      if(res.retCode == 1){
        if(_self.path == 'index'){
          _self.item.logoImgUrl = res.retObject.defaultImgDetail.path
          _self.item.logoImgId = res.retObject.imgId
        }
        if(_self.path == 'category'){
          _self.item.catalogLogoImgUrl = res.retObject.defaultImgDetail.path
          _self.item.catalogParentLogoImgId = res.retObject.imgId
        }
        if(_self.path == 'categoryChild'){
          _self.item.catalogLogoImgUrl = res.retObject.defaultImgDetail.path
          _self.item.catalogLogoImgId = res.retObject.imgId
        }
      }else{
        _self.$message.error(res.retMsg)
      }
    },
  }
}
</script>
<style scoped lang="sass">
/deep/ .el-form-item__content img
  max-width: inherit
  max-height: inherit
/deep/ .el-upload--picture-card
  width: 100px
  line-height: inherit
/deep/ .el-upload-list--picture-card .el-upload-list__item
  width: 100px
  height: 100px
</style>